package com.example.star.mapper;

import com.example.star.entity.Favorite;
import com.example.star.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface ShoppingCartMapper {
    @Insert("INSERT INTO shopping_carts (username,imageResource, starName, title, productType, prices, freight, deliveryAddress,shoppingAddress,quantity,totalPrice) " +
            "VALUES (#{userName},#{imageResource}, #{starName}, #{title}, #{productType}, #{prices}, #{freight}, #{deliveryAddress},#{shoppingAddress},#{quantity},#{totalPrice})")
    void insertShoppingCart(ShoppingCart shoppingCart);

    @Select("SELECT * FROM shopping_carts")
    List<ShoppingCart> getAllShoppingCarts();

    @Select("SELECT * FROM shopping_carts WHERE username = #{userName}")
    List<ShoppingCart> getShoppingCartByuserName(String userName);

    @Select("SELECT * FROM shopping_carts LIMIT #{offset}, #{limit}")
    List<ShoppingCart> getShoppingCartsByPage(@Param("offset") int offset, @Param("limit") int limit);
    @Select("SELECT COUNT(*) FROM shopping_carts")
    int getTotalShoppingCarts();
    @Delete("DELETE FROM shopping_carts WHERE id = #{id}")
    void deleteShoppingCartById(int id);

    // 分页查询指定用户的信息
    @Select("SELECT * FROM shopping_carts WHERE username = #{userName} LIMIT #{offset}, #{limit}")
    List<ShoppingCart> getShoppingCartsByUserPage(@Param("userName") String userName, @Param("offset") int offset, @Param("limit") int limit);

    // 获取指定用户的总数
    @Select("SELECT COUNT(*) FROM shopping_carts WHERE username = #{userName}")
    int getTotalShoppingCartsByUser(@Param("userName") String userName);
}
